package com.longge;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-03-09 23:59
 */
public class SmallerNumbersThanCurrent {
    public int[] smallerNumbersThanCurrent(int[] nums) {
        int n = nums.length;
        int[][] data = new int[n][2];
        for (int i = 0; i < nums.length; i++) {
            data[i][0] = nums[i];
            data[i][1]=i;
        }
        Arrays.sort(data,Comparator.comparing(d->d[0]));

        int pre = -1;
        for (int i = 0; i < data.length; i++) {
            if (pre==-1||data[i-1][0]!=data[i][0]){
                pre=i;
            }
            nums[data[i][1]] = pre;
        }
        return nums;

    }


}
